<?php 
require_once dirname(__FILE__) . '/DAL/SimpleSelect.php';
require_once dirname(__FILE__) . '/DAL/OneToOneInsert.php';
$id = intval($_REQUEST["id"]);
if($id > 0) {
	//es un update -> obtenngo los valores seteados en los campos
}else{
	//es uno nuevo
}
if(isset($_POST) && count($_POST) > 0 && isset($_POST["submit"])) {
    
        $tableName = "usuarios";
        $insertOneToOne = new OneToOneInsert($tableName);
        $insertOneToOne->begin();
           $insertOneToOne->addNameValueFieldPair("id_pais", $_POST["send"]["pais"]);   $insertOneToOne->addNameValueFieldPair("nombre", $_POST["send"]["name"]);   $insertOneToOne->addNameValueFieldPair("apellido", $_POST["send"]["surname"]);   $insertOneToOne->addNameValueFieldPair("activo", $_POST["send"]["active"]);   $insertOneToOne->addNameValueFieldPair("id_avatar", $_POST["send"]["avatar"]);
       
        $insertOneToOne->end();
        $insertOneToOne->execute();    
}
?>
<!DOCTYPE html>
<html>
<head>
    <title></title>
<meta charset="UTF-8">
<meta name="description" content="" />
<!-- Javascript calls -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script>window.jQuery || document.write("<script src='Libraries/jquery.1.7.1/jquery.1.7.1.min.js'>\x3C/script>")</script>
 
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<script type="text/javascript" src="Libraries/UIComponents/js/prettify.js"></script>                                   <!-- PRETTIFY -->
<script type="text/javascript" src="Libraries/UIComponents/js/kickstart.js"></script>                                  <!-- KICKSTART -->
<link rel="stylesheet" type="text/css" href="Libraries/UIComponents/css/kickstart.css" media="all" />                  <!-- KICKSTART --> 

    <!-- Css calls -->
    <link href="Layout/css/miyagi.generator.form.styles.css" rel="stylesheet" />
<!-- CUSTOM STYLES -->
</head>
<body><a id="top-of-page"></a><div id="wrap" class="clearfix">
<form class="vertical" action="" method="POST" 
	enctype="multipart/form-data">
	<div class="col_4">

<div class="formElement">
    <label for="">Pais:
        
<?php
$select = new SimpleSelect();
$select->select(array("nombre", "id" => "codigo", ))
        ->from("pais");
$select->execute();
$optionData = $select->getResultsAsObjectArray();
?>        <select name="send[pais]" 
                id="" 
                class="fancy " >
            <?php
            foreach ($optionData as $option) {
                $value = $option->codigo;
                $text = $option->nombre;
                $checked = ($data["id_pais"] ==  $value ) ? "selected='selected'" : "";
                ?>
                <option <?php echo $checked; ?> value="<?php echo $value; ?>"><?php echo $text; ?></option>
            <?php } ?>        </select>
    </label>
</div>
<div class="formElement">
    <label>Nombre:
    <input type="text" name="send[name]" 
            id="" 
            value="<?php echo $data["nombre"]; ?>" 
            class="" />
    </label>
</div><div class="formElement">
    <label>Apellido:
    <input type="text" name="send[surname]" 
            id="" 
            value="<?php echo $data["apellido"]; ?>" 
            class="" />
    </label>
</div><div class="formElement">
    <label for="">Activo:
        <select name="send[active]" 
                id="" 
                class="fancy " >
                            <option <?php echo ($data["activo"] == S) ? "selected='selected'" : ""; ?> value="S">Si</option>
                            <option <?php echo ($data["activo"] == N) ? "selected='selected'" : ""; ?> value="N">No</option>
                    </select>
    </label>
</div>
<div class="formElement">
    <label class="left">Avatar:  </label>
	
	<div class="imagePreviewContainer" data-element="preview_avatar">
	    <img class="style3" src="Layout/images/emptyImage_96x96.png" width="100" height="100" alt="" title="" />
	    <p class="imagePath"></p>
	</div>
	
        <input type="hidden" name="send[avatar]" 
            id="" 
            value="<?php echo $data["id_avatar"]; ?>" 
            class="" />
	<img onclick="CKFinder.popup( { 
					basePath : 'Library/ckfinder/',
					startupPath : 'Images:/',
					selectActionFunction: setImageField,
					selectThumbnailActionFunction : setImageField
					} ) ;" class="openFolder" src="Layout/images/openFolder.png" alt="" title="" />
  
</div><!--
<div class="formElement submitButtonContainer">
    <input type="submit" name="submit" value="Guardar" />
</div>
-->
<input type="submit" name="submit" value="Guardar" />
    </div>
</form>


<!-- ===================================== START FOOTER ===================================== -->
<div class="clear"></div>
<div id="footer">
    &copy; Copyright 2011–2012 All Rights Reserved. This website was built with <i>Miyagi Generator</i></a>
<a id="link-top" href="#top-of-page">Top</a>
</div>

</div><!-- END WRAP -->
</body></html>